package com.lynn.salary.dao;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public interface ICommonDao {

	void setConnection(Connection conn);

	/**
	 * 通过主键获取对象
	 * 
	 * @param <T>
	 * @param c
	 * @param id
	 * @return
	 * @throws SQLException
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @throws NoSuchMethodException 
	 */
	<T> T getById(Class<T> c, Serializable id) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	/**
	 * 获取对象部分属性
	 * 
	 * @param <T>
	 * @param c
	 * @param part
	 *            属性数组
	 * @param id
	 * @return
	 * @throws SQLException
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @throws NoSuchMethodException 
	 */
	<T> Map<String, Object> getPartById(Class<T> c, String[] part,
			Serializable id) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> List<T> getList(Class<T> c, String condition) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> List<Map<String, Object>> getPartList(Class<T> c, String[] part,
			String condition) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> List<Map<String, Object>> getPartList(Class<T> c, String[] part,
			String condition,Object ... values) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	
	<T> T save(Class<T> c, Map<String, Object> data) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> T save(T o) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> boolean update(Class<T> c, Map<String, Object> data)
			throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> boolean update(T o) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> boolean deleteById(Class<T> c, Serializable id) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	<T> boolean delete(Class<T> c, String condition) throws SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	List<Map<String, Object>> executeSQL(String sql) throws SQLException;
	
	void executeUpdateSQL(String sql) throws Exception;
	
	List<Map<String, Object>> prepareExecuteSQL(String sql, Object... objects) throws SQLException ;
	
	void prepareExecuteUpdateSQL(String sql, Object ... values) throws SQLException;
	
	<T> List<T> conver(Class<T> clazz,List<Map<String,Object>> data) throws Exception;
}
